﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Pages_BusEdit : System.Web.UI.Page
{
	private Int64 BusID { get { return DS.ToInt64(Request.QueryString["id"]); } }

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			InitControls();
		}
	}

	protected void InitControls()
	{
		Bus bus = DBEntity<Bus>.Load(BusID);
		if (bus != null)
		{
			tbBusName.Text = bus.Name;
			tbPlacesCount.Text = bus.PlaceCount.ToString();
		}
	}

	protected void btnCancel_Click(object sender, EventArgs e)
	{
		Response.Redirect(ResolveUrl("~/Pages/BusView.aspx"));
	}

	protected void btnSave_Click(object sender, EventArgs e)
	{
		Bus bus2add = new Bus();
		if (BusID > 0 && DBEntity<Bus>.Load(BusID) != null)
			bus2add.Id = BusID;

		bus2add.Name = tbBusName.Text.Trim();
		bus2add.PlaceCount = DS.ToInt(tbPlacesCount.Text);

		bus2add.Merge();
		Response.Redirect(ResolveUrl("~/Pages/BusView.aspx"));
	}
}